package com.zgm.ch04.applicationContext.resource._9_10;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.core.io.Resource;

public class ResourceDemo {

	public static void main(String[] args) throws Exception {
		ApplicationContext ctx = new ClassPathXmlApplicationContext("com/zgm/ch04/applicationContext/resource/_9_10/_9_10-context.xml");
		
		Resource res1 = ctx.getResource("file:D://a.txt");
//		Resource res1 = ctx.getResource("file:///D://a.txt");
		displayInfo(res1);
		
		Resource res2 = ctx.getResource("classpath:com/zgm/ch04/applicationContext/resource/_9_10/_9_10-context.xml");
		displayInfo(res2);
		
		Resource res3 = ctx.getResource("http://www.google.co.uk");
		displayInfo(res3);
	}
	
	public static void displayInfo(Resource res) throws Exception {
		System.out.println("clazz: " + res.getClass());
		System.out.println("URL: " + res.getURL());
		System.out.println("content: " + res.getURL().getContent());
		System.out.println("URI: " + res.getURI());
		System.out.println("file: " + res.getFile());
		System.out.println("fileName: " + res.getFilename());
		System.out.println("");
	}
}
